package com.example.springworkfront.controller;

import com.alibaba.fastjson.JSON;
import com.example.springworkfront.pojo.Data;
import com.example.springworkfront.pojo.Units;
import com.example.springworkfront.Service.InitServices;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/household")
public class DataController {
    @RequestMapping("/getdata")
    public String getdata() {
        int global_total = 0;
        int global_add = 0;
        int china_total = 0;
        int china_add = 0;
        for (Units units : InitServices.unitsList) {
            global_total += units.getLatestTotalCases();
            global_add += units.getDiffFromPrevDay();
        }
        for (Units units : InitServices.keyList) {
            china_total += units.getLatestTotalCases();
            china_add += units.getDiffFromPrevDay();
        }
        Data data = new Data(String.valueOf(global_total), String.valueOf(global_add),
                String.valueOf(china_total), String.valueOf(china_add));
        String json = JSON.toJSONString(data);
        return json;
    }

}
